package com.puman.action;

import java.io.File;
import java.util.List;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import com.core.BaseAction;
import com.util.UploadDownUtil;

public class FileUploadAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -994819442405597932L;
	
	private  List<File> file;
	private  List<String> fileFileName;
	/**单个文件上传**/
	public void uploadFile(){
		try {
			System.out.println("开始上传1"+fileFileName+"**");
			String name = UploadDownUtil.upload(file, fileFileName, "image").get(0);
			String path = ServletActionContext.getRequest().getContextPath();
			path = path.replace("oil_web", "");
			path=path+"oil_web/image/";
			JSONObject oo = new JSONObject();
			oo.accumulate("file_url", path+name);
			oo.accumulate("img_name", name);
			ajaxJson("status", 0,"data", oo.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void uploadFileDoc(){
		try {
			System.out.println("开始上传1"+fileFileName+"**");
			String name = UploadDownUtil.upload(file, fileFileName, "doc").get(0);
			String path = ServletActionContext.getRequest().getContextPath();
			path = path.replace("oil_web", "");
			path=path+"oil_web/doc/";System.out.println("path...."+path);
			JSONObject oo = new JSONObject();
			oo.accumulate("file_url", path+name);
			oo.accumulate("doc_name", name);
			ajaxJson("status", 0,"data", oo.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public List<File> getFile() {
		return file;
	}
	public void setFile(List<File> file) {
		this.file = file;
	}
	public List<String> getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(List<String> fileFileName) {
		this.fileFileName = fileFileName;
	}

	
}
